<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="redis" uri="http://www.shopjsp.com/redisTag/functions" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="basePath" value="${redis:getSysConfig('base_path_back')}"/>
<c:set var="uploadPath" value="${redis:getSysConfig('uploadFileVisitRoot')}"/>
<script type="text/javascript">
    /**
     * 自定义验证规则
     */
    function validateForm(){
        form.bootstrapValidator({
            message: "无效的值",
            feedbackIcons: {
                valid: "glyphicon glyphicon-ok",
                invalid: "glyphicon glyphicon-remove",
                validating: "glyphicon glyphicon-refresh"
            },
            fields: {
                imageInfo_1: {
                    validators: {
                        notEmpty: {message: "请上传图片"},
                        file:{maxSize: 1024*1024, message: '请上传一张最大不超过1M的jpg/png/gif图片文件'}
                    }
                },
                levelDiscountValue: {
                    validators: {
                    	stringLength: {max: 2,message: "等级折扣值最大长度为2"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                },
                minRefValue: {
                    validators: {
                        stringLength: {max: 10,message: "最小参考值（元）最大长度为10"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                },
                maxRefValue: {
                    validators: {
                        stringLength: {max: 10,message: "最大参考值（元）最大长度为10"},
                        numeric: {
                            message: '只能输入数字'
                        }
                    }
                }
            }
        });
    }

    /**
     * 添加等级策略
     */
	<shiro:hasPermission name="back_gotoBuyersStrategyPage_add">
		function addInfo(){
			$("#myModalLabel").empty().text("添加等级策略信息");
			/**清空隐藏域的值**/
			$("#buyersLevelId").val("");
			$("#buyerRank").val("");
			$("#imageUrl_1").val("");
			resetAddForm();
			/**如果有上传图片功能添加此代码，否则可以去掉**/
			initImageForAdd(1,"sys_shop","image_customer",1,50,50);
		}
	</shiro:hasPermission>

    /**
     * 编辑等级策略
     */
	<shiro:hasPermission name="back_gotoBuyersStrategyPage_update">
		function editInfo(){
			$("#myModalLabel").empty().text("修改等级策略信息");
			/**获取选中行的id**/
			var selectedRow= $("#tt").bootstrapTable('getSelections');
			if(selectedRow.length==1){
				var id=selectedRow[0].buyersLevelId;
				$("#btn_edit").attr("data-target","#addOrEditModal");/**选中了记录后才可打开对应的模态框**/
				$.ajax({
					type: "POST",
					dataType: "JSON",
					url: "${basePath}/back/buyersStrategy/getBuyersStrategyInfo.sjson",
					data: {buyersLevelId:id},
					success: function(result){
						var data = JSON.parse(result.data);
						/**隐藏域**/
						$("#imageUrl_1").val(data.levelIcon);
						$("#buyersLevelId").val(data.buyersLevelId);
						$("#buyerRank").val(data.buyerRank);
						/**可见表单控件**/
						$("#buyersLevel").val(data.buyersLevel);
						$("#minRefValue").val(data.minRefValue);
						$("#maxRefValue").val(data.maxRefValue);
						$("#levelDiscountValue").val(data.levelDiscountValue);
					   /**回写预览上传文件所需的信息，如果有上传图片功能添加此代码，否则可以去掉**/
						initImageForUpdate(1,"sys_shop","image_customer",1,50,50,"${uploadPath}",data.levelIcon);
						reValidateForm();
						removeValidateField('imageInfo_1');
					}
				});
			}else{
				$("#btn_edit").attr("data-target", "");/**没有选中记录不可打开模态框**/
				showMsg("请选择一行记录！");
			}
		}
	</shiro:hasPermission>
</script>

<!--添加编辑模态框（Modal） -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
	<div class="modal-dialog" style="width:70%">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
				<h5 class="modal-title" id="myModalLabel"></h5>
			</div>
			<div class="modal-body">

				<form id="form1"  method="post" action="${basePath}/back/buyersStrategy/saveOrUpdateRatingBuyersStrategy.sjson">
					<input id="buyersLevelId" type="hidden" name="buyersLevelId" noclear="true"/>
					<input id="buyerRank" type="hidden" name="buyerRank" noclear="true"/>

					<table align="center" class="addOrEditTable table-bordered table" style="width:100%;">
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>等级图标:</td>
							<td class="toleft_td" colspan="3">
								<div class="container">
									<input id="imageUrl_1" type="hidden" name="levelIcon" value=""/>
									<div class="form-group" id="fileWrap1"></div>
								</div>
								<span style="color:red">提示：请上传规格宽72px，高15px的图片</span>
							</td>
						</tr>

						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>会员等级:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<select class="form-control input-sm"  id="buyersLevel" name="buyersLevel" >
										<option value="">--请选择--</option>
										<c:forEach items="${redis:getBasicKeyBook('buyersStrategyLevel')}" var="bkb" >
											<option id="opt_${bkb.value}" value="${bkb.value}">
												${bkb.name}
											</option>
										</c:forEach>
									</select>
									<script type="text/javascript">
										$("#buyersLevel").change(function(){
											$("#buyerRank").val($("#opt_"+$(this).val()).text());
										});
									</script>
								</div>
							</td>
							<td class="toright_td" width="150px"><span style="color:red">* </span>等级折扣值:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="levelDiscountValue" name="levelDiscountValue" placeholder="请输入等级折扣值"/>
								</div>
							</td>
						</tr>
						<tr>
							<td class="toright_td" width="150px"><span style="color:red">* </span>最小参考值（元）:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="minRefValue" name="minRefValue" placeholder="请输入最小参考值（元）"/>
								</div>
							</td>
							<td class="toright_td" width="150px"><span style="color:red">* </span>最大参考值（元）:&nbsp;&nbsp;</td>
							<td  class="toleft_td">
								<div class="form-group">
									<input type="text" class="form-control input-sm" id="maxRefValue" name="maxRefValue" placeholder="请输入最大参考值（元）"/>
								</div>
							</td>
						</tr>
					</table>
				</form>
			</div>
			<div class="modal-footer">
				<button type="button" id="validateBtn" class="btn btn-primary"  onclick="submitForm()">保存</button>
				<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
			</div>

		</div><!-- /.modal-content -->
	</div><!-- /.modal -->
</div>